﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Langexplr.Abc;
using System.IO;

namespace AbcLibrary.Tests
{
    [TestFixture]
    public class TypeEncodingTests
    {
        [Test]
        public void TestS24Encoding()
        {
            byte[] content = new byte[3];
            content[0] = 3;
            content[1] = 23;
            content[2] = 100;
            int aValue;
            using (MemoryStream ms = new MemoryStream(content))
            {
                using (BinaryReader reader = new BinaryReader(ms))
                {
                    aValue = TypeEncodingUtilities.ReadS24Value(reader);
                }
            }
            byte[] targetContent = new byte[3];
            using (MemoryStream ms = new MemoryStream(targetContent))
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                {
                    TypeEncodingUtilities.WriteS24Value(aValue, writer);
                }
            }
            Assert.AreEqual(content[0], targetContent[0]);
            Assert.AreEqual(content[1], targetContent[1]);
            Assert.AreEqual(content[2], targetContent[2]);
        }


        [Test]
        public void TestU30Encoding()
        {
           

            byte[] targetContent = new byte[3];
            using (MemoryStream ms = new MemoryStream(targetContent))
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                {
                    TypeEncodingUtilities.WriteU30Value(1325, writer);
                }
            }

            byte[] content = new byte[3];

            uint aValue;
            using (MemoryStream ms = new MemoryStream(targetContent))
            {
                using (BinaryReader reader = new BinaryReader(ms))
                {
                    aValue = TypeEncodingUtilities.ReadU30Value(reader);
                }
            }

            Assert.AreEqual(1325,aValue);
           
        }
    }
}
